package com.webwork.lims.system.dataobject;

import java.util.ArrayList;
import java.util.List;

import com.webwork.lims.common.dataobject.SuperEnum;

public enum Role implements SuperEnum {

	NOSET(SuperEnum.NOSET_CODE, SuperEnum.NOSET_MSG),

	/**
	 * 系统管理员
	 */
	ADMIN(1, "系统管理员"),
	/**
	 * 企业用户
	 */
	BUSINESS(2, "企业用户"),
	/**
	 * 客户用户
	 */
	CUSTOMER(3, "客户用户"),
	/**
	 * 配送员
	 */
	DELIVERY(4, "配送员"),
	/**
	 * 审核员
	 */
	VERIFY(5, "审核员");
	
	private Integer code;
	private String msg;
	
	private Role(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	@Override
	public Integer getCode() {
		return code;
	}
	
	@Override
	public String getMsg() {
		return msg;
	}
	
	public static Role[] useableValues() {
		List<Role> ret = new ArrayList<Role>();
		for (Role o : Role.values()) {
			if (o.code == Role.NOSET_CODE) {
				continue;
			}
			ret.add(o);
		}
		return ret.toArray(new Role[ret.size()]);
	}
	
	public static Role fromCode(Integer code) {
		for (Role o : Role.values()) {
			if (o.code.equals(code)) {
				return o;
			}
		}
		throw new IllegalArgumentException(code.toString());
	}

}
